package chaoyue.study.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 使用配置的方式声明交换机和队列
 */
@Configuration
public class RabbitMQConfig {
    @Bean
    public Queue testQueue() {
        return new Queue("queue1", true);
    }

    @Bean
    public DirectExchange testExchange() {
        return new DirectExchange("exchange1", true, false);
    }

    @Bean
    public Binding binding(Queue testQueue, DirectExchange testExchange) {
        return BindingBuilder.bind(testQueue).to(testExchange).with("key1");
    }
}
